package com.jumi.microservice.service.usercash.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.common.page.TableDataInfo;
import com.jumi.microservice.common.utils.EnumUtil;
import com.jumi.microservice.dto.reponse.JmUserReponse;
import com.jumi.microservice.dto.userWallet.WalletInOrOutListRequest;
import com.jumi.microservice.dto.userWallet.WalletInOrOutListResponse;
import com.jumi.microservice.dto.userWallet.WalletInOrOutRequest;
import com.jumi.microservice.entity.CpsUserWallet;
import com.jumi.microservice.enumerate.CpsWalletTypeEnum;
import com.jumi.microservice.enums.FenXiaoType;
import com.jumi.microservice.mapper.CpsUserWalletMapper;
import com.jumi.microservice.service.IMemberService;
import com.jumi.microservice.service.usercash.admin.AdminCapitalDetailsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author by mazhao
 * @Classname WalletInOrOutService
 * @Description TODO
 * @Date 2020/7/22 10:47
 */
@Service
public class CpsWalletInOrOutService {

    @Resource
    CpsUserWalletMapper userWalletMapper;
    /**
     * 前台获取钱包收支明细
     *
     * @param request
     * @return
     */
    public TableDataInfo<List<WalletInOrOutListResponse>> getWalletInOrOutList(WalletInOrOutListRequest request) {
        TableDataInfo tableDataInfo = new TableDataInfo();
        List<WalletInOrOutListResponse> result = new ArrayList<>();
        IPage<CpsUserWallet> page = new Page<>(request.getPageNum(), request.getPageSize());
        QueryWrapper<CpsUserWallet> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("del_flag", 0).eq("user_id", request.getUserId())
                .orderByDesc("create_time");
        IPage<CpsUserWallet> records = userWalletMapper.selectPage(page, queryWrapper);
        List<CpsUserWallet> list = records.getRecords();
        for (CpsUserWallet userWallet : list) {
            WalletInOrOutListResponse walletInOrOutListResponse = new WalletInOrOutListResponse();
            walletInOrOutListResponse.setAmount(userWallet.getAmount());
            CpsWalletTypeEnum walletTypeEnum = EnumUtil.getByCode(userWallet.getType(), CpsWalletTypeEnum.class);
            walletInOrOutListResponse.setDescription(walletTypeEnum.getMsg());
            walletInOrOutListResponse.setTime(userWallet.getCreateTime());
            result.add(walletInOrOutListResponse);
        }
        tableDataInfo.setTotal(records.getTotal());
        tableDataInfo.setRows(result);
        return tableDataInfo;
    }

}
